﻿using System;

namespace DBMock.Builders
{
    /// <summary>
    /// 字符串整数builder
    /// </summary>
    public class StrIntBuilder : Builder
    {
        private int min; //最小值
        private int max; //最大值
        private string format; //格式

        /// <summary>
        /// 初始化StrNumberBuilder
        /// </summary>
        /// <param name="seed">随机数种子</param>
        /// <param name="min">最小值</param>
        /// <param name="max">最大值</param>
        /// <param name="format">格式</param>
        public StrIntBuilder(int seed, int min, int max, string format)
            : base(seed)
        {
            if (min > max)
            { throw new Exception("Minimum is larger than maximum."); }

            this.min = min;
            this.max = max;
            this.format = format;
        }

        public override object Build()
        {
            int num = random.Next(min, max);

            return string.IsNullOrEmpty(format) ?
                num.ToString() :
                num.ToString(format);
        }
    }
}
